clear 
clear matrix
clear mata
set more off
set maxvar 32767
set matsize 11000
pause on 
cls

* load HRS data at the hhidpn-wave level 
use respondent_level_hrs, clear

* whether have kids who will help in the future with LTC
gen d_rhlpfutnb=1 if rhlpfutkn>0 & !missing(rhlpfutkn)
replace d_rhlpfutnb=0 if rhlpfutkn==0 

* set time variable
tsset hhidpn wave 

* treat as a user if report to use NH at all in any of the next three waves
gen rnhuser2_short=.
replace rnhuser2_short=1 if f.rnrshom==1
replace rnhuser2_short=1 if f2.rnrshom==1
replace rnhuser2_short=1 if f3.rnrshom==1

* treat as a non-user if never use NH in the next three waves while alive
replace rnhuser2_short=0 if missing(f.wave) & missing(f2.wave) & missing(f3.wave)
replace rnhuser2_short=0 if f.rnrshom==0 & missing(f2.wave) & missing(f3.wave)
replace rnhuser2_short=0 if f.rnrshom==0 & f2.rnrshom==0 & missing(f3.wave)
replace rnhuser2_short=0 if f.rnrshom==0 & f2.rnrshom==0 & f3.rnrshom==0 
replace rnhuser2_short=. if wave>=10

* define income group
by hhidpn, sort: gen rtemp=_n==1
egen y1u_temp=pctile(ritot_avg) if rtemp==1, p(33)
egen y2u_temp=pctile(ritot_avg) if rtemp==1, p(66)

egen y1u = max(y1u_temp)
egen y2u = max(y2u_temp)

qui gen y_gr=.
qui replace y_gr=1 if !missing(ritot_avg) & ritot_avg<=y1u
qui replace y_gr=2 if !missing(ritot_avg) & ritot_avg>y1u & ritot_avg<=y2u
qui replace y_gr=3 if !missing(ritot_avg) & ritot_avg>y2u

* type definition: income group x availability of informal care from children
gen type=1 if y_gr==1 & d_rhlpfutnb==0
replace type=2 if y_gr==2 & d_rhlpfutnb==0
replace type=3 if y_gr==3 & d_rhlpfutnb==0
replace type=4 if y_gr==1 & d_rhlpfutnb==1
replace type=5 if y_gr==2 & d_rhlpfutnb==1
replace type=6 if y_gr==3 & d_rhlpfutnb==1

* formal LTC usage measure
gen ynh = rnhuser2_short

*====================================================
* stats used in the analysis
*====================================================
* [pr_y] type distribution 
tab type 

* Table A.4: [pr_fc] formal LTC risk 
tabstat ynh if ragey_b>=70 & ragey_b<=85, by(type) s(mean count)

* [empirical LTCI demand by income] coverage rate among those able to buy
tabstat rhiltc if radla==0 & riadla==0 & rstrok==0 & rnhmliv==0 & rnrshom==0 & rhomcar==0  & ragey_b<=79, by(y_gr) s(mean)

* [empirical LTCI demand by family care availability] coverage rate among those able to buy
tabstat rhiltc if radla==0 & riadla==0 & rstrok==0 & rnhmliv==0 & rnrshom==0 & rhomcar==0  & ragey_b<=79, by(d_rhlpfutnb) s(mean)

* [empirical correlation btw LTC risk and insurance ownership]
tabstat ynh if ragey_b>=70 & ragey_b<=85, by(rhiltc) s(mean count)

* conditional on having LTCI, type distribution & LTC risk
tab type if rhiltc==1
tabstat ynh if rhiltc==1 & ragey_b>=70 & ragey_b<=85, by(type) s(mean count)


